//function performLogin() {
//    if ($('#username').val().length > 0 && $('#password').val().length > 0) {
//        return true;//AJAX here - login form action submit (maybe return false and login without reload)
//    } else {
//        alert("Incorrect login/password");
//        return false;
//    }
//}

$(document).ready(function() {
    $('#login-form').submit(function() {
        var username = $('#username').val();
        var password = $('#password').val();
        
        // Sprawdzamy czy użytkownik podał dane.
        if (username != '' && password != '') {
            $.ajax({
                method: 'post',
                url: 'loginAjax.do',
                data: {
                    username: username,
                    password: password
                },
                success: function(result) {
                    if (result.trim() === 'OK') {
                        // TODO: ustawić ciasteczko.
                        window.location.replace('mainPage.do');
                    } else {
                        alert('Incorrect username or password, please try again.');
                    }
                }
            });
        } else {
            alert('Please enter username and password.');
        }
        
        return false;
    });
});